package org.springcloud.wisdom.springcloud_03_freshman.admin.service;

import org.springcloud.wisdom.springcloud_03_freshman.admin.dao.AdminGoodsDao;
import org.springcloud.wisdom.springcloud_03_freshman.common.bean.Page;
import org.springcloud.wisdom.springcloud_03_freshman.student.entity.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AdminGoodsService {
    @Autowired
    AdminGoodsDao adminGoodsDao;

    /**
     * 以分页的形式获取物品领取的情况
     * @param pageNum 页数
     * @param pageSize 记录数
     * @param receiveStatus 领取的状态
     * @param dept 学生所属院系
     * @return
     */
    public Page<Goods> getGoodsPage(int pageNum, int pageSize, String receiveStatus, Integer dept){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Goods> list=adminGoodsDao.getGoodsByCons(start,pageSize,receiveStatus,dept);
        //获取总条目数
        int total=adminGoodsDao.countGoods(receiveStatus,dept);
        //计算总页数
        int pages =(total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Goods> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }
}
